package com.ruoyi.basic.controller;

import com.ruoyi.api.system.utils.ShiroUtils;
import com.ruoyi.api.system.utils.poi.ExcelUtil;
import com.ruoyi.basic.domain.BasicPost;
import com.ruoyi.basic.domain.BasicRemind;
import com.ruoyi.basic.domain.BasicUser;
import com.ruoyi.basic.service.IBasicRemindService;
import com.ruoyi.basic.service.IBasicUserService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 行政职务Controller
 * 
 * @author ruoyi
 * @date 2021-12-06
 */
@Controller
@RequestMapping("/basic/remind")
public class BasicRemindController extends BaseController
{
    private String prefix = "basic/remind";

    @Autowired
    private IBasicRemindService basicRemindService;

    @Autowired
    private IBasicUserService basicUserService;

    @RequiresPermissions("basic:remind:view")
    @GetMapping()
    public String remind()
    {
        return prefix + "/remind";
    }

    /**
     * 查询人员提醒列表
     */
    @RequiresPermissions("basic:remind:list")
    @PostMapping("/remindList")
    @ResponseBody
    public TableDataInfo remindList(BasicRemind basicRemind)
    {
        startPage();
        List<BasicRemind> list = basicRemindService.selectBasicRemindAllList(basicRemind);
        return getDataTable(list);
    }

    /**
     * 导出员工技术职务
     */
    @Log(title = "用户提醒", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasicRemind basicRemind)
    {
        List<BasicRemind> list = basicRemindService.selectBasicRemindAllList(basicRemind);
        ExcelUtil<BasicRemind> util = new ExcelUtil<BasicRemind>(BasicRemind.class);
        return util.exportExcel(list, "用户提醒信息数据");
    }

    @RequiresPermissions("basic:remind:add")
    @GetMapping("/{userId}")
    public String add(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        BasicUser basicUser = basicUserService.selectBasicUserById(userId);
        mmap.put("user", basicUser);
        return prefix + "/add";
    }

    /**
     * 保存用户提醒
     */
    @RequiresPermissions("basic:remind:add")
    @Log(title = "用户提醒", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasicRemind basicRemind)
    {
        basicRemind.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(basicRemindService.insertBasicRemind(basicRemind));
    }

    /**
     * 修改人员提醒
     */
    @RequiresPermissions("basic:remind:edit")
    @GetMapping("/edit/{remindId}")
    public String edit(@PathVariable("remindId") Long remindId, ModelMap mmap)
    {
        BasicRemind basicRemind = basicRemindService.selectBasicRemindByRemindId(remindId);
        mmap.put("basicRemind", basicRemind);
        return prefix + "/edit";
    }

    /**
     * 修改保存人员提醒
     */
    @RequiresPermissions("basic:remind:edit")
    @Log(title = "用户提醒", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasicRemind basicRemind)
    {
        basicRemind.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(basicRemindService.updateBasicRemind(basicRemind));
    }

    /**
     * 删除用户提醒
     */
    @RequiresPermissions("basic:remind:remove")
    @Log(title = "用户提醒", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basicRemindService.deleteBasicRemindByRemindIds(ids));
    }

    /**
     * 查询行政职务列表
     */
    @RequiresPermissions("basic:remind:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list()
    {
        BasicRemind basicRemind = new BasicRemind();
        basicRemind.setRemindDate(DateUtils.getDate());
        startPage();
        List<BasicRemind> list = basicRemindService.selectBasicRemindList(basicRemind);
        return getDataTable(list);
    }

    /**
     * 用户提醒标记已处理
     */
    @RequiresPermissions("basic:remind:edit")
    @Log(title = "用户提醒", businessType = BusinessType.OTHER)
    @GetMapping( "/handle/{remindId}")
    @ResponseBody
    public AjaxResult handle(@PathVariable("remindId") Long remindId)
    {
        return toAjax(basicRemindService.handleBasicRemindByRemindId(remindId));
    }
}
